#pragma once

#include <windows.h>  
#include "KeyEventArgs.h"
#include "Events.h"

using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Diagnostics;

namespace GTA
{
	private ref class KeyboardHook
	{
		
	private:
		delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam);

		static HookProc^ _procKeyboard = gcnew HookProc(OnKeyboardHook);
		static HookProc^ _procMouse = gcnew HookProc(OnMouseHook);

		static IntPtr OnKeyboardHook(int nCode, IntPtr wParam, IntPtr lParam);
		static IntPtr OnMouseHook(int nCode, IntPtr wParam, IntPtr lParam);
		
		static IntPtr KeyboardHookHandle;
		static IntPtr MouseHookHandle;

		literal int altPressedFlag = 1 << 29;
		literal int beingReleasedFlag = 1 << 31;
		static bool isHooked;


	public:
		static bool AttachHook(bool isglobal,IntPtr hmodule, System::UInt32 threadid);
		static void DetachHook();

	public:

		[DllImport("user32.dll", CharSet = CharSet::Auto, SetLastError = true)]
		static IntPtr SetWindowsHookEx(int idHook, HookProc ^lpfn, IntPtr hMod, System::UInt32 dwThreadId);

		[DllImport("User32.DLL", CharSet = CharSet::Auto, SetLastError = true)]
		static Boolean^ UnhookWindowsHookEx(IntPtr^ hHook) ;

		[DllImport("user32.dll", CharSet = CharSet::Auto, SetLastError = true)]
		static IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);

		[DllImport("kernel32.dll", CharSet = CharSet::Auto, SetLastError = true)]
		static IntPtr GetModuleHandle(System::String ^lpModuleName);


	};
};
